import com.demo.computer.Computer;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Assert;


public class IOCtest {
    ApplicationContext  ctx;
    @Before
    public void init(){
        this.ctx =
                new ClassPathXmlApplicationContext(
                        "classpath:applicationContext.xml");
    }

    @Test
    public void testIOC(){
        Computer computer = this.ctx.getBean("computer",Computer.class);
        Assert.notNull(computer);
        System.out.println(computer.toString());
    }

    @Test
    public void testComputer(){
        Computer computer1 = this.ctx.getBean("computer",Computer.class);
        Computer computer2 = this.ctx.getBean("computer",Computer.class);
        Computer computer3 = this.ctx.getBean("computerByArgs",Computer.class);
        Assert.notNull(computer1);
        Assert.notNull(computer2);
        Assert.notNull(computer3);
        Assert.state(computer1 != computer2);
        Assert.state(computer2 != computer3);
    }


}
